<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVCWeb.Models.ViewData.MenuNewViewData>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Edit</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
   <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->

    <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $("#MenuForm").validate({
                rules:
            {
                MenuName:
                {
                    required: true
                },
                Link:
                {
                    required: true
                },
                SortOrder:
                {
                    required: true,
                    digits: true
                }
            },

                messages:
            {
                MenuName:
                {
                    required: "Menu name must be entered"
                },
                Link:
                {
                    required: "Link must be entered"
                },
                SortOrder:
                {
                    required: "Sort Order must be entered",
                    digits: "Sort Order must be only digits"
                }
            }
            });
            $("#submit_view").click(function() {
                $("#IsRedirectToView").val("true");
            });
        });
    </script>

    <h2>
        Edit Menu</h2>
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm("Edit", "Menu", FormMethod.Post, new { id = "MenuForm" }))
       {%>
    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="MenuName">
                Menu Name:</label>
            <%= Html.TextBox("MenuName",ViewData.Model.Menu.MenuName) %>
            <%= Html.ValidationMessage("MenuName", "*") %>
        </p>
        <p>
            <label for="Link">
                Link:</label>
            <%= Html.TextBox("Link", ViewData.Model.Menu.Link)%>
            <%= Html.ValidationMessage("Link", "*") %>
        </p>
        <p>
            <label for="Type">
                Menu type:</label>
            <%= Html.DropDownList("Type", new SelectList(ViewData.Model.Types, "Type", "Type",ViewData.Model.Menu.Type))%>
        </p>
        <p>
            <label for="Type">
                Or create new menu type:</label>
            <%= Html.TextBox("NewType") %>
            <%= Html.ValidationMessage("NewType", "*")%>
        </p>
        <p>
            <label for="IsRoot">
                Is root menu:</label>
            <%= Html.CheckBox("IsRoot", ViewData.Model.Menu.ParentMenuId == 0) %>
        </p>
        <p>
            <label for="ParentMenuId">
                or is child of parent menu:</label>
            <%= Html.DropDownList("ParentMenuId",new SelectList(ViewData.Model.Parents, "MenuId", "MenuName"))%>
            <%= Html.ValidationMessage("ParentMenuId", "*") %>
        </p>
        <p>
            <label for="SortOrder">
                Sort order:</label>
            <%= Html.TextBox("SortOrder", ViewData.Model.Menu.SortOrder.HasValue ? ViewData.Model.Menu.SortOrder.Value : 1) %>
            <%= Html.ValidationMessage("SortOrder", "*") %>
        </p>
        <p>
            <label for="Active">
                Active:</label>
            <%= Html.CheckBox("Active", ViewData.Model.Menu.Active.HasValue ?  ViewData.Model.Menu.Active.Value : false)%>
            <%= Html.ValidationMessage("Active", "*") %>
        </p>
        <p>
            <label for="Desc">
                Description:</label>
            <%= Html.TextArea("Desc", ViewData.Model.Menu.Desc)%>
            <%= Html.ValidationMessage("Desc", "*") %>
        </p>
        <p>
            <%= Html.Hidden("IsRedirectToView")%>
            <input id="submit" name="submit" type="submit" value="Update" />
            <input id="submit_view" name="submit_view" type="submit" value="Update & View" />            
            <input type="reset" value="Reset" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%=Html.ActionLink("Back to List", "Index") %>
    </div>
</asp:Content>
